//
//  YYMusicMeetTableViewCell.swift
//  STMusic
//
//  Created by stoneobs on 2017/6/14.
//  Copyright © 2017年 stoneobs. All rights reserved.
//

import UIKit

class YYMusicMeetTableViewCell: UITableViewCell {
    static var cellHeight:CGFloat = 105;
    
    var indexLable:STLabel?
    
    var titleLable:STLabel?
    
    var iconImageView:UIImageView?
    
    var nickNameLable:STLabel?
    
    
    var listenButtton:STButton?
    
    
    var model:YYMeetModel = YYMeetModel(){
        
        didSet{
            
            self.indexLable?.text = model.indexString;
            
            self.titleLable?.text = model.playlist_name;
            
            self.iconImageView?.sd_setImage(with: URL.init(string: model.pimg!), placeholderImage: PeopleImage, options: .retryFailed);
            
            self.nickNameLable?.text = model.username;
            
            let str:NSString = NSString.init(string: model.username!);
            
            self.nickNameLable?.width = str.widthWithheight(12, font: 12);
            
            if (self.nickNameLable?.width)! > CGFloat(200.0) {
                self.nickNameLable?.width = 200.0;
            }
            
            self.listenButtton?.left = (self.nickNameLable?.right)! + 20;
            
            self.listenButtton?.setTitle(model.play_count, for: .normal);
            
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubview();
        self.backgroundColor = UIColor.white.withAlphaComponent(0.7);
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        self.indexLable = STLabel.init(frame: .init(x: 35, y: 0, width: 25, height: 13),
                                       text: "1",
                                       textColor: ThirdTextColor,
                                       font: 13,
                                       isSizetoFit: false,
                                       textAlignment: .left);
        self.indexLable?.centerY = CGFloat(YYMusicArticleTableViewCell.cellHeight/2);
        self.addSubview(self.indexLable!);
        
        self.titleLable = STLabel.init(frame: .init(x: 15 + (self.indexLable?.right)!, y: 25, width: SCREEN_WIDTH - 50 - 20, height: 17),
                                       text: "房东的猫：把美好事物走完",
                                       textColor: FirstTextColor,
                                       font: 15,
                                       isSizetoFit: false,
                                       textAlignment: .left);
        self.addSubview(self.titleLable!);
        
        
        self.iconImageView = UIImageView.init(frame: .init(x: (self.titleLable?.left)!, y: (self.titleLable?.bottom)! + 15, width: 20, height: 20));
        self.iconImageView?.clipsToBounds = true;
        self.iconImageView?.layer.cornerRadius = 10;
        self.addSubview(self.iconImageView!);
        
        self.nickNameLable = STLabel.init(frame: .init(x: 5 + (self.iconImageView?.right)!, y: 25, width: SCREEN_WIDTH - 50 - 20, height: 13),
                                          text: "房东的猫：把美好事物走完",
                                          textColor: ThirdTextColor,
                                          font: 12,
                                          isSizetoFit: false,
                                          textAlignment: .left);
        self.nickNameLable?.centerY = (self.iconImageView?.centerY)!;
        self.addSubview(self.nickNameLable!);
        
        
        self.listenButtton = STButton.init(frame: CGRect.init(x: (self.nickNameLable?.right)! + 20, y: (self.titleLable?.bottom)! + 15, width: 70, height: 14),
                                           title: "999",
                                           titleColor: ThirdTextColor,
                                           titleFont: 13,
                                           cornerRadius: 0,
                                           backgroundColor: .clear,
                                           backgroundImage: nil,
                                           image: UIImage.init(named: "btn_listen"));
        self.listenButtton?.contentHorizontalAlignment = .left;
        
        self.listenButtton?.titleEdgeInsets = .init(top: 0, left: 5, bottom: 0, right: 0);
        
        self.listenButtton?.centerY = (self.iconImageView?.centerY)!;
        
        self.addSubview(self.listenButtton!);
        
        
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        
    }

}
